package com.newsmanagement.mapper;

import com.newsmanagement.domain.pojo.WholBatch;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SlauWholBatchMapper {

    /**
     * 根据ID查询批发商批号
     */
    @Select("SELECT " +
            "wb_id as wbId, " +
            "batch_id as batchId, " +
            "whol_id as wholId, " +
            "sb_id as sbId, " +
            "type, " +
            "batch_date as batchDate, " +
            "state, " +
            "remarks " +
            "FROM whol_batch WHERE wb_id = #{wbId}")
    WholBatch selectWholBatchById(@Param("wbId") Integer wbId);

    /**
     * 根据状态查询批发商批号
     */
    @Select("SELECT " +
            "wb_id as wbId, " +
            "batch_id as batchId, " +
            "whol_id as wholId, " +
            "sb_id as sbId, " +
            "type, " +
            "batch_date as batchDate, " +
            "state, " +
            "remarks " +
            "FROM whol_batch WHERE state = #{state} ORDER BY batch_date DESC")
    List<WholBatch> selectWholBatchesByState(@Param("state") Integer state);

    /**
     * 选择性更新批发商批号
     */
    @Update("<script>" +
            "UPDATE whol_batch " +
            "<set>" +
            "  <if test='batchId != null'>batch_id = #{batchId},</if>" +
            "  <if test='wholId != null'>whol_id = #{wholId},</if>" +
            "  <if test='sbId != null'>sb_id = #{sbId},</if>" +
            "  <if test='type != null'>type = #{type},</if>" +
            "  <if test='batchDate != null'>batch_date = #{batchDate},</if>" +
            "  <if test='state != null'>state = #{state},</if>" +
            "  <if test='remarks != null'>remarks = #{remarks},</if>" +
            "</set>" +
            "WHERE wb_id = #{wbId}" +
            "</script>")
    int updateWholBatchSelective(WholBatch wholBatch);
}